home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / C / Snippets / Stuart's Tech Notes / nAppleTalk library bug < prev    next >
Text File  |  1994-12-12  |  3KB  |  44 lines

  1. (C) 1992 Stuart Cheshire <cheshire@cs.stanford.edu>
  2.  
  3. Apple has a serious (crash your Mac) bug in their nAppleTalk library (which is supplied with Think C) so you should use the following Think C assembly code to add and remove routines from the AppleTalk transition queue.
  4.  
  5. Why would you want to use the AppleTalk transition queue? Firstly, it tells your program when the user switches network connection, eg from LocalTalk to Ethernet, so your program can continue working without a restart, but more importantly, it tells your program whenever a PowerBook goes to sleep or wakes up again.
  6.  
  7. If you are writing networking code and DON'T pay attention to AppleTalk transitions, then if your software is run on a PowerBook, it will will die when the PowerBook is put to sleep, and will not reactivate when the PowerBook is woken up again. This generally requires that the user restarts the Mac (or at least your program) to get your software working again, and is not very user friendly.
  8.  
  9. For an example of how to use the AppleTalk transition queue, see "ATP sample code".
  10.  
  11. --------------------------
  12. // Simply include this code fragment in your program and change
  13. // LAPAddATQ & LAPRmvATQ calls to my_LAPAddATQ & my_LAPRmvATQ.
  14.  
  15. extern pascal OSErr my_LAPAddATQ(ATQEntryPtr theATQEntry);
  16. extern pascal OSErr my_LAPRmvATQ(ATQEntryPtr theATQEntry);
  17.  
  18. static void assembler(void)
  19.     {
  20.     asm    {
  21.     extern my_LAPAddATQ:
  22.             move.w    #LAddAEQ, d0
  23.             bra.s    @1
  24.     extern my_LAPRmvATQ:
  25.             move.w    #LRmvAEQ, d0
  26.         @1    move.l    4(sp), a0
  27.             move.l    LAPMgrPtr, a1
  28.             move.l    (sp)+, (sp)
  29.             jsr        2(a1)
  30.             move.l    (sp)+, a0
  31.             move.w    d0, (sp)
  32.             jmp        (a0)
  33.         }
  34.     }
  35. --------------------------
  36.  
  37. The difference between this code and Apple's code in the nAppleTalk library is simply the deletion of an erroneous minus sign. In the second to last line, the Apple code says "move.w d0, -(sp)" instead of "move.w d0, (sp)". If called from a routine without a stack frame (no parameters or local variables) then this will crash your Mac -- and at the very least it will give your program strange and unpredictable behaviour which is hard to debug.
  38.  
  39. I informed Symantec of this bug in September 1992. Symantec told me it was not their bug and told me to send it to Apple, so I informed Apple. Apple denied that there was any bug and basically told me, "don't call us, we'll call you." They never did call me.
  40.  
  41. It is pretty sad that after Apple's system programmers worked so hard to implement a useful system feature, Apple's library programmers messed it up so that developers who try to use it are rewarded with a nightmare debugging session trying to find a bug that isn't even in their code and can only be found by single stepping through Apple's library in MacsBug. I hate to think how many programmers may have tried to use this and given up, unable to make their programs work. Even more worrying is that the bug managed to exist for so many years and I was the first person to find it, which would seem to suggest that no one inside Apple tried to write any code that uses the AppleTalk transition queue either, or if they did, they never found why it didn't work.
  42.  
  43. It's also pretty sad that Apple has fallen so far since the early days. Fifty guys designed and built the Macintosh and wrote all the System Software plus some pretty good applications in a year. Now 10000 employees can't fix a one-character bug in a year even when they are told about it.
  44.